import 'package:acgn_pioneer/models/sort_comic_model.dart';

import '../public.dart';

class SortService {
  static Future<List<SortComicModel>> getTopSearch() async {
    return await ACGN.http.fetch<SortComicModel>(
      ACGN.config.interfaceApi.gettopsearch,
    );
  }

  // 获取分类漫画
  static Future<List<SortComicModel>> getSortlist(
      {String key, // 关键词
      String orderby, // 排序
      String man, // 性别
      String status, // 状态
      String type, // 类型
      int page = 1,
      int pagesize = 10}) async {
    var re = await ACGN.http.fetch(ACGN.config.interfaceApi.getsortlist,
        isParse: false,
        queryParameters: {
          'search_key': key,
          'orderby': orderby,
          'page': page,
          'pagesize': pagesize,
          'status_id': status,
          'comic_sort': type,
          'human_type': man,
        });
    List<SortComicModel> lst = List<SortComicModel>();
    (re['data'] as List<dynamic>).forEach((var element) {
      lst.add(SortComicModel.fromJson(element));
    });
    return lst;
  }

// 获取筛选类型列表
  static Future<List<SimpleKeyModel>> getSortConfig() async {
    List<dynamic> re = await ACGN.http
        .fetch(ACGN.config.interfaceApi.getsortconfig, isParse: false);
    List<SimpleKeyModel> list = List<SimpleKeyModel>();
    re.forEach((item) {
      list.add(SimpleKeyModel(
          label: item['name'],
          key: item['urlid'],
          value: item['id'].toString()));
    });
    return list;
  }
}
